Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(katana): rename starknet config to execution config #2557

Merged
merged 1 commit into from
Oct 19, 2024

Conversation

kariy
Copy link
Member

@kariy kariy commented Oct 19, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a new execution configuration structure for improved clarity and management of invocation and validation steps.
    • Added constants for maximum recursion depth and default execution steps.
  • Bug Fixes

    • Updated default values for maximum steps in the execution configuration to enhance performance.
  • Refactor

    • Consolidated configuration management by replacing the previous structure with a more streamlined execution configuration.
    • Removed deprecated structures and fields to simplify the codebase.
  • Documentation

    • Updated documentation to reflect changes in configuration management and execution parameters.

Copy link

coderabbitai bot commented Oct 19, 2024

Walkthrough

Ohayo, sensei! This pull request introduces significant changes to the configuration management within the Katana project. It consolidates the StarknetConfig structure into a new ExecutionConfig structure, which includes fields for maximum invocation and validation steps. The NodeArgs struct is updated to reflect this change, along with various related files. The dojo-test-utils crate also sees modifications in how configurations are imported and utilized. Additionally, several constants are removed, and a new module for execution configuration is introduced.

Changes

File Path Change Summary
bin/katana/src/cli/node.rs Updated NodeArgs struct to include ExecutionConfig. Changed method signature from starknet_config to execution_config. Updated EnvironmentOptions fields.
crates/dojo-test-utils/src/sequencer.rs Modified import statements and updated TestSequencer methods to use the new Config structure. Changed get_default_test_config to accept SequencingConfig.
crates/katana/core/src/backend/config.rs Removed StarknetConfig and Environment structs along with their associated methods.
crates/katana/core/src/backend/mod.rs Removed config field of type StarknetConfig from Backend struct.
crates/katana/core/src/constants.rs Removed constants: DEFAULT_INVOKE_MAX_STEPS, DEFAULT_VALIDATE_MAX_STEPS, MAX_RECURSION_DEPTH.
crates/katana/node/src/config/dev.rs Removed #[derive(Default)] from DevConfig and provided a custom Default implementation.
crates/katana/node/src/config/execution.rs Introduced ExecutionConfig struct and constants for execution configuration.
crates/katana/node/src/config/mod.rs Added new module execution and updated Config struct to include execution field.
crates/katana/node/src/lib.rs Updated CfgEnv to use config.execution instead of config.starknet.

Possibly related issues

Possibly related PRs


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (5)
crates/katana/node/src/config/execution.rs (2)

1-4: Ohayo, sensei! Constants look good, but could use some documentation.

The constants are well-defined and their names are self-explanatory. However, adding documentation comments would enhance clarity for other developers.

Consider adding doc comments to explain the purpose and any constraints for each constant. For example:

/// Maximum depth of recursion allowed in the execution.
pub const MAX_RECURSION_DEPTH: usize = 1000;

/// Default maximum number of steps allowed for invocation.
pub const DEFAULT_INVOCATION_MAX_STEPS: u32 = 10_000_000;

/// Default maximum number of steps allowed for validation.
pub const DEFAULT_VALIDATION_MAX_STEPS: u32 = 1_000_000;

6-11: Ohayo again, sensei! ExecutionConfig struct looks solid!

The ExecutionConfig struct is well-designed, encapsulating all necessary execution parameters. The public fields allow for easy access and modification, which is appropriate for a configuration struct.

Consider adding more derived traits to enhance the struct's functionality:

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ExecutionConfig {
    // ... existing fields ...
}

Adding PartialEq and Eq would allow for easy comparison between different ExecutionConfig instances, which could be useful in testing or configuration management scenarios.

crates/dojo-test-utils/src/sequencer.rs (3)

10-10: Ohayo, sensei! Consider using more specific imports.

The wildcard import pub use katana_node::config::*; brings in all public items from the config module. While this simplifies import management, it may reduce code clarity and potentially introduce naming conflicts.

Consider explicitly importing only the necessary items from katana_node::config to improve code readability and maintainability. For example:

use katana_node::config::{Config, SequencingConfig, /* other specific items */};

This approach makes it clearer which items are being used from the config module.


Line range hint 36-54: Ohayo, sensei! The changes look good, but let's add some documentation.

The modification to accept a Config parameter in the start method improves flexibility in configuring the test sequencer. This change aligns well with the broader refactoring of the configuration structure.

Consider adding or updating the method documentation to reflect this change. For example:

/// Starts a new TestSequencer with the given configuration.
///
/// # Arguments
///
/// * `config` - The configuration to use for the sequencer.
///
/// # Returns
///
/// A new `TestSequencer` instance.
pub async fn start(config: Config) -> Self {
    // ... existing implementation ...
}

This documentation will help other developers understand how to use the updated method.


Line range hint 114-131: Ohayo, sensei! The changes look great, but let's make it even clearer.

The modification to accept a SequencingConfig parameter in the get_default_test_config function enhances flexibility in configuring the sequencing behavior while maintaining default values for other configurations. This change aligns well with the broader refactoring of the configuration structure.

To improve clarity, consider adding a comment explaining the purpose of this function and the significance of the SequencingConfig parameter. For example:

/// Returns a default test configuration with custom sequencing settings.
///
/// This function allows specifying custom sequencing configuration while using
/// default values for other configuration aspects such as dev settings, chain
/// specification, and RPC configuration.
///
/// # Arguments
///
/// * `sequencing` - Custom sequencing configuration to be used in the test setup.
pub fn get_default_test_config(sequencing: SequencingConfig) -> Config {
    // ... existing implementation ...
}

This additional documentation will help other developers understand the purpose and usage of this function more easily.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 76fb0b7 and d6a0037.

📒 Files selected for processing (9)
  • bin/katana/src/cli/node.rs (6 hunks)
  • crates/dojo-test-utils/src/sequencer.rs (1 hunks)
  • crates/katana/core/src/backend/config.rs (0 hunks)
  • crates/katana/core/src/backend/mod.rs (0 hunks)
  • crates/katana/core/src/constants.rs (0 hunks)
  • crates/katana/node/src/config/dev.rs (2 hunks)
  • crates/katana/node/src/config/execution.rs (1 hunks)
  • crates/katana/node/src/config/mod.rs (2 hunks)
  • crates/katana/node/src/lib.rs (1 hunks)
💤 Files with no reviewable changes (3)
  • crates/katana/core/src/backend/config.rs
  • crates/katana/core/src/backend/mod.rs
  • crates/katana/core/src/constants.rs
🧰 Additional context used
🔇 Additional comments (15)
crates/katana/node/src/config/execution.rs (1)

13-21: Domo, sensei! Default implementation is on point!

The Default trait implementation for ExecutionConfig is well-done. It correctly uses the constants defined earlier to set default values, allowing for easy creation of a default ExecutionConfig instance.

This implementation will be particularly useful when creating new configurations or when you need a base configuration to modify. Good job!

crates/katana/node/src/config/dev.rs (3)

2-2: Ohayo, sensei! LGTM on the struct definition changes.

The removal of #[derive(Default)] from the DevConfig struct is a good move. It allows for more precise control over the default values of the struct fields, which is consistent with the manual implementation of Default added later in the file.


25-29: Ohayo again, sensei! The manual Default implementation looks great!

The explicit implementation of the Default trait for DevConfig is a solid choice. Setting both fee and account_validation to true by default ensures that fee charging and account validation are enabled in the development configuration. This approach provides more flexibility for future modifications if needed.


Line range hint 2-29: Ohayo once more, sensei! Let's verify the impact of these changes.

While the default behavior of DevConfig remains unchanged, it's crucial to ensure that no existing code relies directly on the #[derive(Default)] attribute. These changes improve code maintainability and readability by making the default values explicit.

To confirm that these changes don't introduce any issues, please run the following script:

If the script returns any results, please review those occurrences to ensure they still work as expected with the new manual Default implementation.

✅ Verification successful

Ohayo once more, sensei! Since the previous search didn't find any direct usages of DevConfig::default(), let's dive a bit deeper to ensure everything's in order. Please run the following script:

This will help verify that there are no hidden usages or implicit dependencies on the Default trait for DevConfig.


Ohayo once more, sensei! Since the previous script encountered an error, let's adjust our approach to ensure we capture all necessary instances. Please run the following scripts:

If the first command returns any results, please review those occurrences to ensure that #[derive(Default)] is no longer used for DevConfig. The second command should ideally return no results, confirming that all DevConfig instances explicitly set their fields.


Ohayo once more, sensei! Great news – the DevConfig struct doesn't use the derived Default trait, and there are no direct calls to DevConfig::default(). With all instantiations explicitly setting fields, your changes maintain the default behavior without introducing any issues.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any direct usage of Default::default() on DevConfig

# Test: Search for direct usage of Default::default() on DevConfig
rg --type rust "DevConfig::default\(\)" crates

Length of output: 48


Script:

#!/bin/bash
# Description: Search for any instantiation of DevConfig without explicit field values

# Using ast-grep to find instances where DevConfig is instantiated without setting fields
ast-grep --lang rust --pattern $'DevConfig { $$$ }' crates

# Additionally, check for any #[derive(Default)] implementations on DevConfig
ast-grep --lang rust --pattern $'#[derive(Default)]\nstruct DevConfig { $$$ }' crates

Length of output: 721


Script:

#!/bin/bash
# Description: Ensure `DevConfig` does not use the derived Default trait and all instantiations set fields explicitly

# 1. Check for any #[derive(Default)] on DevConfig
rg --type rust '#\[derive\s*\(.*Default.*\)\]\s*pub\s+struct\s+DevConfig' crates

# 2. Confirm all `DevConfig` instantiations explicitly set fields
rg --type rust 'DevConfig\s*::\s*default\s*\(\)' crates

Length of output: 140

crates/katana/node/src/config/mod.rs (3)

Line range hint 1-58: Ohayo once more, sensei! Overall changes look great.

The refactoring from StarknetConfig to ExecutionConfig and the introduction of the execution module align well with the PR objectives. These changes suggest a move towards a more generic and potentially extensible execution configuration system.

A few points to consider:

  1. Ensure that all parts of the codebase that previously used StarknetConfig have been updated to use ExecutionConfig.
  2. Update any documentation or comments that might reference the old configuration structure.
  3. Consider adding a brief comment explaining the rationale behind this refactoring, which could be helpful for future maintainers.

Great work on this refactoring, sensei! It should improve the flexibility and maintainability of the configuration system.


37-38: Ohayo again, sensei! Field update in Config struct looks solid.

The replacement of starknet: StarknetConfig with execution: ExecutionConfig is consistent with the refactoring objectives. This change suggests a more generic and potentially extensible approach to execution configuration.

To ensure a smooth transition, let's verify that all usages of the old starknet field have been updated throughout the codebase:

#!/bin/bash
# Description: Verify that all usages of the old 'starknet' field have been updated

# Test: Search for any remaining references to 'config.starknet' or 'Config::starknet'
rg --type rust -e 'config\.starknet' -e 'Config::starknet'

If this search returns any results, please update those occurrences to use config.execution or Config::execution as appropriate.


3-3: Ohayo, sensei! New module import looks good.

The addition of the execution module and the import of ExecutionConfig align well with the refactoring objectives. This change improves the organization of the configuration structure.

To ensure completeness, let's verify the contents of the new execution module:

Also applies to: 10-10

✅ Verification successful

Ohayo, sensei! It looks like there was a typo in the previous script. Let's try running the corrected script to verify the ExecutionConfig struct:


Ohayo, sensei! Let's search the entire codebase to locate the ExecutionConfig struct:


Ohayo, sensei! The ExecutionConfig struct is correctly defined in the execution module. Everything looks good with the recent changes.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the contents of the new execution module

# Test: Check if the ExecutionConfig is defined in the execution module
ast-grep --lang rust --pattern 'struct ExecutionConfig { $$$' crates/katana/node/src/config/execution.rs

Length of output: 340


Script:

#!/bin/bash
# Description: Verify the contents of the new execution module

# Test: Check if the ExecutionConfig is defined in the execution module
ast-grep --lang rust --pattern 'struct ExecutionConfig { $$$' crates/katana/node/src/config/execution.rs

Length of output: 451


Script:

#!/bin/bash
# Description: Search for the ExecutionConfig struct across the codebase

rg --type rust 'struct ExecutionConfig' .

Length of output: 117

crates/katana/node/src/lib.rs (1)

167-169: Ohayo, sensei! LGTM: Execution config refactor looks great!

The changes align perfectly with the PR objective of renaming the starknet config to execution config. The CfgEnv initialization now uses config.execution instead of config.starknet, which improves clarity and consistency throughout the codebase. The functionality remains unchanged, ensuring a smooth transition.

bin/katana/src/cli/node.rs (7)

28-30: Ohayo, sensei! Importing execution configuration constants.

The addition of ExecutionConfig, DEFAULT_INVOCATION_MAX_STEPS, and DEFAULT_VALIDATION_MAX_STEPS to the imports is appropriate and sets up the execution configuration correctly.


192-192: Ohayo, sensei! Updating default for validate_max_steps.

Changing the default value to DEFAULT_VALIDATION_MAX_STEPS ensures consistency with the new execution configuration.


197-197: Ohayo, sensei! Updating default for invoke_max_steps.

Updating the default value to DEFAULT_INVOCATION_MAX_STEPS aligns with the new configuration structure.


287-291: Ohayo, sensei! Incorporating execution into the node configuration.

Adding execution to the Config struct ensures that execution parameters are properly included in the node's configuration.


351-356: Ohayo, sensei! Implementing the execution_config method.

The new execution_config method correctly constructs an ExecutionConfig with the appropriate invocation_max_steps and validation_max_steps values.


500-501: Ohayo, sensei! Updating tests for default execution parameters.

The test cases accurately verify the default values for invocation_max_steps and validation_max_steps in the execution configuration.


532-533: Ohayo, sensei! Updating tests for custom execution parameters.

The test cases correctly validate custom values for invocation_max_steps and validation_max_steps, ensuring that the configuration accepts and applies user-provided values.

Copy link

codecov bot commented Oct 19, 2024

Codecov Report

Attention: Patch coverage is 88.88889% with 3 lines in your changes missing coverage. Please review.

Project coverage is 69.45%. Comparing base (76fb0b7) to head (d6a0037).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
crates/katana/node/src/lib.rs 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2557      +/-   ##
==========================================
- Coverage   69.79%   69.45%   -0.35%     
==========================================
  Files         396      397       +1     
  Lines       51160    51222      +62     
==========================================
- Hits        35709    35577     -132     
- Misses      15451    15645     +194     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant